#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <math.h>

#include "dominion.h"
#include "dominion_helpers.h"
#include "rngs.h"

void test_mine_effect()
{
	struct gameState state;
	int currentPlayer;
	int choice1, choice2;
	int handPos;

	currentPlayer = 0;

	state.handCount[currentPlayer] = 2;

	/* Test One: pay copper, gain silver */
	choice1 = copper;
	choice2 = silver;
	handPos = 0;
	currentPlayer = 0;

	int silver_count = 1;

	state.hand[currentPlayer][choice1] = copper;
	state.hand[currentPlayer][choice2] = silver;

	cardEffect(mine, choice1, choice2, 0, &state, handPos, 0);

	int gained_silver = 0;
	int i;

	for (i = 0; i < state.handCount[currentPlayer]; i++) {
		if (state.hand[currentPlayer][i] == silver) {
			gained_silver = 1;
		}
	}

	if (gained_silver) {
		printf("Test One: PASS\n");
	}
	else {
		printf("Test One: FAIL - did not attain silver\n");
	}

	/* Test Two: discard silver, get gold */
	choice1 = silver;
	choice2 = gold;

	state.hand[currentPlayer][choice1] = silver;
	state.hand[currentPlayer][choice2] = gold;

	cardEffect(mine, choice1, choice2, 0, &state, handPos, 0);

	int gained_gold = 0;

	for (i = 0; i < state.handCount[currentPlayer]; i++) {
		if (state.hand[currentPlayer][i] == silver) {
			gained_silver = 1;
		}
	}

	if (gained_gold) {
		printf("Test Two: PASS\n");
	}
	else {
		printf("Test Two: FAIL - did not attain gold\n");
	}

	/* Test Three: Discarding the choice1 card */
	for (i = 0; i < state.handCount[currentPlayer]; i++) {
		if (state.hand[currentPlayer][i] == silver) {
			silver_count--;
		}
	}

	if (silver_count == 0) {
		printf("Test Three: PASS\n");
	}
	else {
		printf("Test Three: FAIL - did not discard copper");
	}

	/* Test Four: Discarding the mine card */
	if (state.handCount[currentPlayer] == 1) {
		printf("Test Four: PASS\n");
	}
	else {
		printf("Test Four: FAIL - did not discard mine card\n");
	}
}

int main(void)
{
	test_mine_effect();
	return EXIT_SUCCESS;
}